package com.wiscamp.ninechapters.panels.infrastructure.mappers;

import com.wiscamp.ninechapters.panels.infrastructure.po.UserRolePO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public interface UserRoleMapper extends JpaRepository<UserRolePO, Long>, JpaSpecificationExecutor<UserRolePO> {
    @Query(value = "select p from UserRolePO p where p.userId = :userId and p.roleId = :roleId")
    UserRolePO findByUserAndRole(long userId, long roleId);

    @Query(value = "select p.roleId from UserRolePO p where p.userId = :userId")
    Collection<Long> findRoleIdsByUser(long userId);
}
